/****************************************************************************
 *
 *  ALi (Shanghai) Corporation, All Rights Reserved. 2007 Copyright (C)
 *
 *  File: mp_subtitle_txt.c
 *
 *  Description: This file describes txt file operations.
 *
 *  History:
 *      Date        	Author      	Version  		Comment
 *      ====        	======      =======  	=======
 *  1.  2009.5.29  Martin_Xia  	0.0.1  		
 *
 ****************************************************************************/

#include <types.h>
#include <retcode.h>
#include <api/libc/printf.h>

#include <api/libc/string.h>
#include <osal/osal.h>
#include <api/libfs2/stat.h>
#include <api/libfs2/dirent.h>
#include <api/libfs2/statvfs.h>
#include <api/libfs2/unistd.h>
#include <api/libfs2/stdio.h>

#include <api/libmp/media_player_api.h>
#include <api/libmp/mp_subtitle_api.h>
#include "mp_subtitle_vobsub.h"
#include "mp_subtitle.h"



#define MP_ENABLE_IGNORE_TXT_TAG
/**********************Global  Variables***********************************/
//define the Global  Variables

//#define MP_SUB_DEBUG	libc_printf	//Ben Debug

/**************************Static  Function Declare***********************************/
static void mp_subtitle_parse_utf8_txt(MpSubtitle *p,char *str, unsigned long *pos, unsigned long *time);
static void mp_subtitle_parse_unicode_txt(MpSubtitle *p, wchar_t *str, unsigned long *pos, unsigned long *time);

/****************************API  Function ***********************************/
/////////////////////////////////////////////////////////////////////////////
// mp_subtitle_parse_txt
//
// Description:
//	API function. Parse unicode txt subtitle file.
//
// Arguments:
//	sub - Subtitle handle
//	str - Pointer to a txt file in memory
//	pos - Store every offset for each subtitle in a txt file
//	time - Store every time for each subtitle in a txt file
//	
// Return Value:
//	None
//
/////////////////////////////////////////////////////////////////////////////

void mp_subtitle_parse_txt(void *sub, char *str, unsigned long *pos, unsigned long *time)
{	
	MpSubtitle				*p;
	
	MP_SUB_DEBUG("====>>mp_subtitle_parse_txt()\n");

	if ((!sub)||(!str)||(!pos)||(!time))
	{
		MP_SUB_DEBUG("mp_subtitle_parse_txt: Invalid Parameters!\n");
		MP_SUB_DEBUG("<<====mp_subtitle_parse_txt()\n");
		return;
	}


	p = (MpSubtitle*)sub;

	if (p->avail_sub_files[p->current_sub_file_id].avail_file_type != MP_SUBTITLE_TYPE_TXT)
	{
		MP_SUB_DEBUG("mp_subtitle_parse_txt: The subtitle file is not a txt file!\n");
		MP_SUB_DEBUG("<<====mp_subtitle_parse_txt()\n");
		return;
	}

	

	if (p->txt_file.txt_type == MP_SUBTITLE_TXT_TYPE_L_UNICODE)
	{
		mp_subtitle_parse_unicode_txt(p, (wchar_t*)str, pos, time);
	}
	else if ((p->txt_file.txt_type == MP_SUBTITLE_TXT_TYPE_UTF8) || (p->txt_file.txt_type == MP_SUBTITLE_TXT_TYPE_ANSI))
	{
		mp_subtitle_parse_utf8_txt(p, str, pos, time);
	}

	
	MP_SUB_DEBUG("<<====mp_subtitle_parse_txt()\n");
	return;
}


/**************************Internal Static  Function ***********************************/
/////////////////////////////////////////////////////////////////////////////
// mp_subtitle_parse_utf8_txt
//
// Description:
//	Parse utf8 txt subtitle file.
//
// Arguments:
//	sub - Subtitle handle
//	str - Pointer to a txt file in memory
//	pos - Store every offset for each subtitle in a txt file
//	time - Store every time for each subtitle in a txt file
//	
// Return Value:
//	None
//
/////////////////////////////////////////////////////////////////////////////

static void mp_subtitle_parse_utf8_txt(MpSubtitle *p,char *str, unsigned long *pos, unsigned long *time)
{
	char *bol=str;
	char *bot=0,*eot=0,*cot=0;
	long l=0;
	long semicolons;
	char *xtime1,*xtext;
	long tt;
	long long realtime;
	BYTE i,j,sub_format;
	
	fileinfo_video cur_videoinfo;	
	#define SUB_LIKE_SRT_FORMAT		0	//00:02:20,000 --> 00:02:30,000 /r/n abc
	#define SUB_LIKE_TMPLAER_FORMAT	1	//0:00:01:abc /r/n
	#define SUB_LIKE_MICRODVD_FORMAT	2	//{1}{75}abc /r/n
	#define SUB_LIKE_MICRODVD_FORMAT1	3	//[1][75]abc /r/n   //Ben 121123#1

	
	MP_SUB_DEBUG("====>>mp_subtitle_parse_utf8_txt()\n");
	MpgFileGetStreamInfo(&cur_videoinfo);	

	if(*bol<='9'&&*bol>='0')
	{
		if(*(bol+1)=='\r' && *(bol+2)=='\n')
			sub_format = SUB_LIKE_SRT_FORMAT;
		else	
			sub_format = SUB_LIKE_TMPLAER_FORMAT;
	}
	else
	//Ben 121123#1	
	{
		if(*bol == '[')
		{
			sub_format = SUB_LIKE_MICRODVD_FORMAT1;
			cur_videoinfo.FramePeriod = 100000;
		}
		else
			sub_format = SUB_LIKE_MICRODVD_FORMAT;
	}
	MP_SUB_DEBUG("FramePeriod=%d \n",cur_videoinfo.FramePeriod);

	MP_SUB_DEBUG("sub_format=%d \n",sub_format);	
	//Ben 121123#1

	bol = str;
	switch(sub_format)
	{
		case SUB_LIKE_SRT_FORMAT:
			while (*bol)
			{
				if (
					(*(bol+0)=='\r' || *(bol+0)=='\n') &&
					(*(bol+1)=='\r' || *(bol+1)=='\n') &&
					(
						(
						(*(bol+2)=='\r' || *(bol+2)=='\n') &&
						(*(bol+3)=='\r' || *(bol+3)=='\n')

						)
						||
						*(bol+0)==*(bol+1)
					)
				)
				{
					*bol='\0';
					bol++;
					continue;
				}
				if (l>MP_SUBTITLE_MAX_SUB_COUNT-3) break;
				#ifdef MP_ENABLE_IGNORE_TXT_TAG		
				if (*bol=='<') {bot=bol; eot=0;}
				if (*bol=='>') eot=bol;
				#endif
				if (bot && eot && eot-bot<50)
				{
					while (bot!=eot+1) {*bot=' '; bot++;}
					bot=eot=0;
				}
				if (bol==str || *(bol-1)=='\n' || *(bol-1)=='\r')
				{
					cot=bol;
					semicolons=0;
					while (*cot!='\n' && *cot!='\r' && *cot!='\0')
					{
						if (*cot==':') semicolons++;
						cot++;
					}
					if (*cot=='\0') {break;}
					if (semicolons!=4) {bol++;continue;}
					cot=bol;
					while ((*cot<'0' || *cot>'9') && *cot!='\0') cot++;
					if (*cot=='\0') {bol++; continue;}
					xtime1=cot;
					*time=0;
					tt=0; while (*xtime1>='0' && *xtime1<='9') {tt*=10; tt+=(*xtime1-0x30); xtime1++;}; xtime1++;
					*time+=tt; *time*=60;
					tt=0; while (*xtime1>='0' && *xtime1<='9') {tt*=10; tt+=(*xtime1-0x30);xtime1++;}; xtime1++;
					*time+=tt; *time*=60;
					tt=0; while (*xtime1>='0' && *xtime1<='9') {tt*=10; tt+=(*xtime1-0x30);xtime1++;}; xtime1++;
					*time+=tt; *time*=1000;
					tt=0; while (*xtime1>='0' && *xtime1<='9') {tt*=10; tt+=(*xtime1-0x30);xtime1++;}; xtime1++;
					*time+=tt;
					realtime=*time;
					realtime*=TICKSPERSEC;
					//realtime/=1000;
					*time=(unsigned long)realtime;
					time++;
					cot=xtime1;
					while ((*cot<'0' || *cot>'9') && *cot!='\0') cot++;
					if (*cot=='\0') {bol++; continue;}
					xtime1=cot;
					*time=0;
					tt=0; while (*xtime1>='0' && *xtime1<='9') {tt*=10; tt+=(*xtime1-0x30); xtime1++;}; xtime1++;
					*time+=tt; *time*=60;
					tt=0; while (*xtime1>='0' && *xtime1<='9') {tt*=10; tt+=(*xtime1-0x30);xtime1++;}; xtime1++;
					*time+=tt; *time*=60;
					tt=0; while (*xtime1>='0' && *xtime1<='9') {tt*=10; tt+=(*xtime1-0x30);xtime1++;}; xtime1++;
					*time+=tt; *time*=1000;
					tt=0; while (*xtime1>='0' && *xtime1<='9') {tt*=10; tt+=(*xtime1-0x30);xtime1++;}; xtime1++;
					*time+=tt;
					realtime=*time;
					realtime*=TICKSPERSEC;
					//realtime/=1000;
					*time=(unsigned long)realtime;
					MP_SUB_DEBUG("SUB time_stramp = %d \n",*time);	//Ben 111202#1
					time++;
					cot=xtime1;
					while (*cot!='\r' && *cot!='\n' && *cot!='\0') cot++;
					while (*cot=='\r' || *cot=='\n') cot++;
					if (*cot=='\0') {bol++; continue;}
					xtext=cot;
					*pos=cot-str;
					pos++;
					*pos=0;
					pos++;
					l+=2;
				}
				bol++;
			}
			break;
		case SUB_LIKE_TMPLAER_FORMAT:
			while (*bol)
			{
				xtime1=bol;
				*time=0;
				tt=0; while (*xtime1>='0' && *xtime1<='9') {tt*=10; tt+=(*xtime1-0x30); xtime1++;}; xtime1++;
				*time+=tt; *time*=60;
				tt=0; while (*xtime1>='0' && *xtime1<='9') {tt*=10; tt+=(*xtime1-0x30);xtime1++;}; xtime1++;
				*time+=tt; *time*=60;
				tt=0; while (*xtime1>='0' && *xtime1<='9') {tt*=10; tt+=(*xtime1-0x30);xtime1++;}; xtime1++;
				*time+=tt; *time*=1000;		
				realtime=*time;
				realtime*=TICKSPERSEC;
				*time=(unsigned long)realtime;
				
				MP_SUB_DEBUG("TMP time_stramp1 = %d \n",*time);	//Ben 111202#1
				time++;
				
				*pos = xtime1 -str;
				pos++;
				*pos=0;
				pos++;
				l+=2;	
				
				while((!(*(bol+0)=='\r' && *(bol+1)=='\n'))&&(*(bol+0)!='\0'))
					bol++;
				if(*(bol+0)=='\0')
				{
					*time = (unsigned long)realtime + 10000;	//the last subtitle will be hold for 10seconds to keeping show.
					time++;
					break;			
				}
				
				*bol = '\0';//set the string end for each subtile by time stamp.
				bol+=2;//point to next time stamp.

				if(*(bol+0)=='\r' && *(bol+1)=='\n')//that means the end of the whole subtile.
				{
					*time = (unsigned long)realtime + 10000;	//the last subtitle will be hold for 10seconds to keeping show.
					time++;
					break;
				}
				else	
				{
				xtime1=bol;
				*time=0;
				tt=0; while (*xtime1>='0' && *xtime1<='9') {tt*=10; tt+=(*xtime1-0x30); xtime1++;}; xtime1++;
				*time+=tt; *time*=60;
				tt=0; while (*xtime1>='0' && *xtime1<='9') {tt*=10; tt+=(*xtime1-0x30);xtime1++;}; xtime1++;
				*time+=tt; *time*=60;
				tt=0; while (*xtime1>='0' && *xtime1<='9') {tt*=10; tt+=(*xtime1-0x30);xtime1++;}; xtime1++;
				*time+=tt; *time*=1000;		
				realtime=*time;
				realtime*=TICKSPERSEC;		
				*time=(unsigned long)realtime;
				if(realtime > 100)//Ben 121123#1
					*time -= 100;

				MP_SUB_DEBUG("TMP time_stramp2 = %d \n",*time);	//Ben 111202#1
				time++;
				}

				if (l>MP_SUBTITLE_MAX_SUB_COUNT-3) break;
				
			}
			break;
		case SUB_LIKE_MICRODVD_FORMAT:
		case SUB_LIKE_MICRODVD_FORMAT1:	//Ben 121123#1	
			while (*bol)
			{
				xtime1=bol;
				for(i=0;i<2;i++)
				{
					*time=0;
					xtime1++;tt=0; while (*xtime1>='0' && *xtime1<='9') {tt*=10; tt+=(*xtime1-0x30); xtime1++;}; xtime1++;					

					*time+=tt; 
					*time*=cur_videoinfo.FramePeriod;
					//libc_printf("time_stramp1 = %d \n",*time);	//Ben 111202#1
					*time /= 1000;
					MP_SUB_DEBUG("mD time_stramp = %d \n",*time);	//Ben 111202#1
					
					if(*time<1000)
						*time=1000;
					
					realtime=*time;
					realtime*=TICKSPERSEC;
					*time=(unsigned long)realtime;		
					time++;
				}											
				*pos = xtime1 -str;
				pos++;
				*pos=0;
				pos++;
				l+=2;	
				
				while((!(*(bol+0)=='\r' && *(bol+1)=='\n'))&&(*(bol+0)!='\0'))
					bol++;
				if(*(bol+0)=='\0')
					break;			

				if(*(bol+0)=='\r'&&*(bol+1)=='\n'&&*(bol+2)=='\r'&&*(bol+3)=='\n')//end of the last sub by timestamp
				{
					*bol = '\0';
					break;
				}					
				*bol = '\0';//set the string end for each subtile by time stamp.
				bol+=2;//point to next time stamp. 

				if (l>MP_SUBTITLE_MAX_SUB_COUNT-3) break;				
			}			
			break;
	}	
	*str='\0';
	*pos=0xFFFFFFFF;
	*time=0;
	l++;
	p->total_sub_count=l;
	MP_SUB_DEBUG("<<====mp_subtitle_parse_utf8_txt()\n");
}
/////////////////////////////////////////////////////////////////////////////
// mp_subtitle_parse_unicode_txt
//
// Description:
//	Parse unicode txt subtitle file.
//
// Arguments:
//	sub - Subtitle handle
//	str - Pointer to a txt file in memory
//	pos - Store every offset for each subtitle in a txt file
//	time - Store every time for each subtitle in a txt file
//	
// Return Value:
//	None
//
/////////////////////////////////////////////////////////////////////////////
static void mp_subtitle_parse_unicode_txt(MpSubtitle *p, wchar_t *str, unsigned long *pos, unsigned long *time)
{
	wchar_t *bol=str;
	wchar_t *bot=0,*eot=0,*cot=0;
	long l=0;
	long semicolons;
	wchar_t *xtime1,*xtext;
	long tt;
	long long realtime;

	BYTE i,j,sub_format;
	
	fileinfo_video cur_videoinfo;	
	#define SUB_LIKE_SRT_FORMAT		0	//00:02:20,000 --> 00:02:30,000 /r/n abc
	#define SUB_LIKE_TMPLAER_FORMAT	1	//0:00:01:abc /r/n
	#define SUB_LIKE_MICRODVD_FORMAT	2	//{1}{75}abc /r/n
	#define SUB_LIKE_MICRODVD_FORMAT1	3	//[1][75]abc /r/n   //Ben 121123#1
	
	MP_SUB_DEBUG("====>>mp_subtitle_parse_unicode_txt()\n");
	MpgFileGetStreamInfo(&cur_videoinfo);	

	if(*bol<=L'9'&&*bol>=L'0')
	{
		if(*(bol+1)==L'\r' && *(bol+2)==L'\n')
			sub_format = SUB_LIKE_SRT_FORMAT;
		else	
			sub_format = SUB_LIKE_TMPLAER_FORMAT;
	}
	else
	//Ben 121123#1	
	{
		if(*bol == L'[')
		{
			sub_format = SUB_LIKE_MICRODVD_FORMAT1;
			cur_videoinfo.FramePeriod = 100000;
		}
		else
			sub_format = SUB_LIKE_MICRODVD_FORMAT;
	}
	MP_SUB_DEBUG("FramePeriod=%d \n",cur_videoinfo.FramePeriod);

	MP_SUB_DEBUG("sub_format=%d \n",sub_format);	
	//Ben 121123#1
	
	bol = str;
	switch(sub_format)
	{
		case SUB_LIKE_SRT_FORMAT:
			while (*bol)
			{
				if (
					(*(bol+0)==L'\r' || *(bol+0)==L'\n') &&
					(*(bol+1)==L'\r' || *(bol+1)==L'\n') &&
					(
						(
						(*(bol+2)==L'\r' || *(bol+2)==L'\n') &&
						(*(bol+3)==L'\r' || *(bol+3)==L'\n')

						)
						||
						*(bol+0)==*(bol+1)
					)
				)
				*bol=L'\0';
				if (l>MP_SUBTITLE_MAX_SUB_COUNT-3) break;
			#ifdef MP_ENABLE_IGNORE_SRT_TAG				
				if (*bol==L'<') {bot=bol; eot=0;}
				if (*bol==L'>') eot=bol;
			#endif		
				if (bot && eot && eot-bot<50)
				{
					while (bot!=eot+1) {*bot=L' '; bot++;}
					bot=eot=0;
				}
				if (bol==str || *(bol-1)==L'\n' || *(bol-1)==L'\r')
				{
					cot=bol;
					semicolons=0;
					while (*cot!=L'\n' && *cot!=L'\r' && *cot!=L'\0')
					{
						if (*cot==L':') semicolons++;
						cot++;
					}
					if (*cot==L'\0') {break;}
					if (semicolons!=4) {bol++;continue;}
					cot=bol;
					while ((*cot<L'0' || *cot>L'9') && *cot!=L'\0') cot++;
					if (*cot==L'\0') {bol++; continue;}
					xtime1=cot;
					*time=0;
					tt=0; while (*xtime1>=L'0' && *xtime1<=L'9') {tt*=10; tt+=(*xtime1-0x30); xtime1++;}; xtime1++;
					*time+=tt; *time*=60;
					tt=0; while (*xtime1>=L'0' && *xtime1<=L'9') {tt*=10; tt+=(*xtime1-0x30);xtime1++;}; xtime1++;
					*time+=tt; *time*=60;
					tt=0; while (*xtime1>=L'0' && *xtime1<=L'9') {tt*=10; tt+=(*xtime1-0x30);xtime1++;}; xtime1++;
					*time+=tt; *time*=1000;
					tt=0; while (*xtime1>=L'0' && *xtime1<=L'9') {tt*=10; tt+=(*xtime1-0x30);xtime1++;}; xtime1++;
					*time+=tt;
					realtime=*time;
					realtime*=TICKSPERSEC;
					//realtime/=1000;
					*time=(unsigned long)realtime;
					time++;
					cot=xtime1;
					while ((*cot<L'0' || *cot>L'9') && *cot!=L'\0') cot++;
					if (*cot==L'\0') {bol++; continue;}
					xtime1=cot;
					*time=0;
					tt=0; while (*xtime1>=L'0' && *xtime1<=L'9') {tt*=10; tt+=(*xtime1-0x30); xtime1++;}; xtime1++;
					*time+=tt; *time*=60;
					tt=0; while (*xtime1>=L'0' && *xtime1<=L'9') {tt*=10; tt+=(*xtime1-0x30);xtime1++;}; xtime1++;
					*time+=tt; *time*=60;
					tt=0; while (*xtime1>=L'0' && *xtime1<=L'9') {tt*=10; tt+=(*xtime1-0x30);xtime1++;}; xtime1++;
					*time+=tt; *time*=1000;
					tt=0; while (*xtime1>=L'0' && *xtime1<=L'9') {tt*=10; tt+=(*xtime1-0x30);xtime1++;}; xtime1++;
					*time+=tt;
					realtime=*time;
					realtime*=TICKSPERSEC;
					//realtime/=1000;
					*time=(unsigned long)realtime;
					MP_SUB_DEBUG("SUB time_stramp = %d \n",*time);	//Ben 111202#1
					time++;
					cot=xtime1;
					while (*cot!=L'\r' && *cot!=L'\n' && *cot!=L'\0') cot++;
					while (*cot==L'\r' || *cot==L'\n') cot++;
					if (*cot==L'\0') {bol++; continue;}
					xtext=cot;
					*pos=cot-str;
					pos++;
					*pos=0;
					pos++;
					l+=2;
				}
				bol++;
			}
			break;
		case SUB_LIKE_TMPLAER_FORMAT:
			while (*bol)
			{
				xtime1=bol;
				*time=0;
				tt=0; while (*xtime1>=L'0' && *xtime1<=L'9') {tt*=10; tt+=(*xtime1-0x30); xtime1++;}; xtime1++;
				*time+=tt; *time*=60;
				tt=0; while (*xtime1>=L'0' && *xtime1<=L'9') {tt*=10; tt+=(*xtime1-0x30);xtime1++;}; xtime1++;
				*time+=tt; *time*=60;
				tt=0; while (*xtime1>=L'0' && *xtime1<=L'9') {tt*=10; tt+=(*xtime1-0x30);xtime1++;}; xtime1++;
				*time+=tt; *time*=1000;		
				realtime=*time;
				realtime*=TICKSPERSEC;
				*time=(unsigned long)realtime;		
				time++;
				
				*pos = xtime1 -str;
				pos++;
				*pos=0;
				pos++;
				l+=2;	
				
				while((!(*(bol+0)==L'\r' && *(bol+1)==L'\n'))&&(*(bol+0)!=L'\0'))
					bol++;
				if(*(bol+0)==L'\0')
				{
					*time = (unsigned long)realtime + 10000;	//the last subtitle will be hold for 10seconds to keeping show.
					time++;
					break;			
				}
				
				*bol = L'\0';//set the string end for each subtile by time stamp.
				bol+=2;//point to next time stamp.

				if(*(bol+0)==L'\r' && *(bol+1)==L'\n')//that means the end of the whole subtile.
				{
					*time = (unsigned long)realtime + 10000;	//the last subtitle will be hold for 10seconds to keeping show.
					time++;
					break;
				}
				else	
				{
				xtime1=bol;
				*time=0;
				tt=0; while (*xtime1>=L'0' && *xtime1<=L'9') {tt*=10; tt+=(*xtime1-0x30); xtime1++;}; xtime1++;
				*time+=tt; *time*=60;
				tt=0; while (*xtime1>=L'0' && *xtime1<=L'9') {tt*=10; tt+=(*xtime1-0x30);xtime1++;}; xtime1++;
				*time+=tt; *time*=60;
				tt=0; while (*xtime1>=L'0' && *xtime1<=L'9') {tt*=10; tt+=(*xtime1-0x30);xtime1++;}; xtime1++;
				*time+=tt; *time*=1000;		
				realtime=*time;
				realtime*=TICKSPERSEC;
				*time=(unsigned long)realtime;
				if(realtime > 100)//Ben 121123#1
					*time -= 100;
				MP_SUB_DEBUG("TMP time_stramp2 = %d \n",*time);	//Ben 111202#1
				time++;
				}

				if (l>MP_SUBTITLE_MAX_SUB_COUNT-3) break;
				
			}
			break;
		case SUB_LIKE_MICRODVD_FORMAT:
		case SUB_LIKE_MICRODVD_FORMAT1:	//Ben 121123#1	
			while (*bol)
			{
				xtime1=bol;
				for(i=0;i<2;i++)
				{
					*time=0;
					xtime1++;tt=0; while (*xtime1>=L'0' && *xtime1<=L'9') {tt*=10; tt+=(*xtime1-0x30); xtime1++;}; xtime1++;					

					*time+=tt; 
					*time*=cur_videoinfo.FramePeriod;
					//libc_printf("time_stramp1 = %d \n",*time);	//Ben 111202#1
					*time /= 1000;
					MP_SUB_DEBUG("MD time_stramp = %d \n",*time);	//Ben 111202#1
					
					if(*time<1000)
						*time=1000;
					

					realtime=*time;
					realtime*=TICKSPERSEC;
					*time=(unsigned long)realtime;		
					time++;
				}											
				*pos = xtime1 -str;
				pos++;
				*pos=0;
				pos++;
				l+=2;	
				
				while((!(*(bol+0)==L'\r' && *(bol+1)==L'\n'))&&(*(bol+0)!=L'\0'))
					bol++;
				if(*(bol+0)==L'\0')
					break;			

				if(*(bol+0)==L'\r'&&*(bol+1)==L'\n'&&*(bol+2)==L'\r'&&*(bol+3)==L'\n')//end of the last sub by timestamp
				{
					*bol = L'\0';
					break;
				}					
				*bol = L'\0';//set the string end for each subtile by time stamp.
				bol+=2;//point to next time stamp. 

				if (l>MP_SUBTITLE_MAX_SUB_COUNT-3) break;				
			}			
			break;
	}	
	*str=L'\0';
	*pos=0xFFFFFFFF;
	*time=0;
	l++;
	p->total_sub_count=l;
	MP_SUB_DEBUG("<<====mp_subtitle_parse_unicode_txt()\n");
}
